<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar fixed placeholder title="文章详情" left-arrow @click-left="$router.back()" />
    <div class="big-box">
      <!-- 标题栏 -->
      <h2>{{ detail.title }}</h2>
      <!-- 作者信息 -->
      <div class="info-box">
        <!-- 图片 -->
        <van-image fit="cover" round :src="detail.aut_photo" />
        <div class="txt-box">
          <div>{{ detail.aut_name }}</div>
          <div class="time">{{ detail.pubdate | relvTime }}</div>
        </div>
        <van-button size="small" type="info" icon="plus" round>关注</van-button>
      </div>
      <!-- 文章内容 -->
      <div class="content" v-html="detail.content"></div>
    </div>

    <comment />
  </div>
</template>

<script>
// 导入接口
import { detailAPI } from "@/api/article";
// 导入组件
import comment from './comment'
export default {
  components: {
    comment
  },
  data() {
    return {
      detail: {},
    };
  },
  async created() {
    // 页面一打开就发请求
    // 接收路由传递过来的参数，怎么接？$route.query
    // params路径上看不到参数，路径看的到参数的就是 query
    const res = await detailAPI(this.$route.query.id);
    this.detail = res.data;
  },
};
</script>

<style scoped lang="less">
.big-box {
  padding: 20px;
  h2 {
    font-size: 24px;
  }
  .info-box {
    margin-top: 20px;
    display: flex;
    align-items: center;
    .van-image {
      width: 80px;
      height: 80px;
    }

    .txt-box {
      // 让它占用剩余的宽度
      flex: 1;
      margin-left: 10px;
      .time {
        color: gray;
        font-size: 12px;
        margin-top: 10px;
      }
    }
  }
  .content {
    margin-top: 20px;

    // 后代选择器
    // ::v-deep pre {
    //   width: 100%;
    //   overflow: auto;
    //   background-color: black;
    //   color: #fff;
    // }

    // ::v-deep img {
    //   width: 100%;
    // }

    ::v-deep {
      // 在里面写的都是v-deep的后代
      pre {
        width: 100%;
        overflow: auto;
        background-color: black;
        color: #fff;
      }

      img {
        width: 100%;
      }

      code {
        width: 100%;
        word-break: break-all;
      }
    }
  }
}
</style>